using System;
using System.Collections;
using System.Collections.Generic;
namespace Cesium3DTilesSelection

{
    public class RasterOverlayCollection : IEnumerable
    {
        private Tileset _pTileset;
        private List<RasterOverlay> _overlays;
        public int Count;


        public RasterOverlayCollection(Tileset tileset)
        {
            this._pTileset = tileset;
            this._overlays = new List<RasterOverlay>(1);
        }

        /**
   * @brief Adds the given {@link RasterOverlay} to this collection.
   *
   * @param pOverlay The pointer to the overlay. This may not be `nullptr`.
   */
        public void Add(RasterOverlay pOverlay)
        {
            this._overlays.Add(pOverlay);
            pOverlay.loadTileProvider(this._pTileset.externals.pPrepareRendererResources);

            // Add this overlay to existing geometry tiles.

            // this._pTileset->forEachLoadedTile([pOverlayRaw](Tile & tile) {
            // The tile rectangle and geometric error don't matter for a placeholder.
            //     if (tile.getState() != Tile::LoadState::Unloaded)
            //     {
            //         tile.getMappedRasterTiles().(RasterMappedTo3DTile(
            //             pOverlayRaw->getPlaceholder()->getTile(Rectangle(), 0.0)));
            //     }
            // });
        }

        /**
         * @brief Remove the given {@link RasterOverlay} from this collection.
         */
        public void Remove(RasterOverlay pOverlay)
        {

        }

        public IEnumerator GetEnumerator()
        {
            return new RasterOverlayCollectionEnumerator(this._overlays);
        }
    }

    class RasterOverlayCollectionEnumerator : IEnumerator
    {
        public List<RasterOverlay> Collection { get; set; }
        public int position { get; set; }

        public RasterOverlayCollectionEnumerator(List<RasterOverlay> Collection)
        {
            this.Collection = Collection;
            this.position = this.Collection.Count;
        }
        public object Current
        {
            get
            {
                if (this.position == -1 || this.position == this.Collection.Count)
                {
                    throw new InvalidOperationException();
                }
                return this.Collection[this.position];
            }
        }
        public bool MoveNext()
        {
            if (this.position != -1)
            {
                this.position--;
            }
            return this.position > -1;
        }
        public void Reset()
        {
            this.position = this.Collection.Count;
        }
    }
}